<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="node_modules/babel-core/browser.min.js"></script>
</head>
<script type="text/babel">
    console.log(`===================${"object定义"}===================================`);

    let name = "aa";
    let age = 18;
    let json = {name: name, age: age}; // 传统写法
    let json1 = {
        name,
        age,
        showName() { //对象　里不要使用　箭头函数，　this会被变成 window
            return this.name
        },
        showAge(...args) { // 判断三目
            return args[0] == "add" ? age + 1 : age // 可以忽略this
        }
    };
    console.log(json1.showAge("add"));
    console.log(json1.showAge());
    console.log(json1.name)

    console.log(`===================${"object.is"}===================================`);
    let objectIsTest = () => {
        let aa = 1;
        let bb = 1;
        let am = {"a": aa};
        let am1 = am;
        let bm = {"a": bb};
        let bm1 = {"a": bb}
        console.log(Object.is(aa, bb)) // true
        console.log(Object.is(1, bb)) // true
        console.log(Object.is(NaN, NaN))// true

        console.log(Object.is(am, am1)); // true
        console.log(Object.is(am, bm));// false
        console.log(Object.is(bm, bm1)); // false
    };
    objectIsTest();
    console.log(`===================${"object.assign(合并，复制"}==================================`)
    let objectAssign = (...args) => {
        let json = {a: 1};
        let json1 = {b: 2};
        let json2 = {c: 3};
        let json3 = {};
        Object.assign(json3, json, json1, json2);
        console.log(json3); // {a: 1, b: 2, c: 3}
        let json4 = Object.assign({}, json, json1, json2);
        console.log(json4); // {a: 1, b: 2, c: 3}

        json2.a = 111; // todo 改变json2
        json4 = Object.assign({}, json, json1, json2);
        console.log(json4) // {a: 111, b: 2, c: 3} todo 后面的覆盖前面的属性，用于默认值

        let json5 = Object.assign({}, json1)
        console.log(json5); // todo 复制

        let json6 ={...json2}
        console.log(json6) // todo 复制

    };
    objectAssign()
    console.log(`===================${"object 遍历"}==================================`)
    let objectEach = (...args) => {
        // let {keys,value,iterms} = Object
        let json = {a: 1, b: 2, c: 3};
        for (let key of Object.keys(json)) {
            console.log(key)
        }
        for (let [key1,value] of Object.entries(json)) {
            console.log(key1,value)
        }
    };
    objectEach()


</script>
<body>

</body>
</html>